<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="org.teammach.laddercomp.dao.LadderManager"%>
<%@ page import="org.teammach.laddercomp.shared.Ladder"%>
<%@ page import="org.teammach.laddercomp.shared.RoundLadder"%>
<%@ page import="org.teammach.laddercomp.shared.Team"%>

<%@ page import="com.google.appengine.api.datastore.Entity"%>

<%@ page import="java.util.List"%>


<html>
<body>

<%
	LadderManager manager = LadderManager.INSTANCE;
	int round = Integer.parseInt(request.getParameter("Round"));
	RoundLadder roundLadder = manager.getRoundLadder(round);

	if(request.getParameter("actionType") != null && request.getParameter("actionType").equalsIgnoreCase("updateRound")) {
		List<String> teams = roundLadder.getTeams();
		for(int i=0;i<17;i++) {
			teams.set(i, request.getParameter("Team"+i));
		}
		roundLadder.setValid(Boolean.parseBoolean(request.getParameter("valid")));
		manager.updateRoundLadder(roundLadder);
		response.sendRedirect("editRound.jsp?Round="+round);
	}
%>


<p> Updating ladder for round <%=round %> </p>
<form action="">
<%for(int i=0; i<roundLadder.getTeams().size(); i++) { 
	String[] teamNames = new String[] {
			"Adelaide", "Brisbane", "Carlton", "Collingwood", "Essendon", "Fremantle","Geelong",
			"Gold Coast", "Hawthorn", "Melbourne",
			 "North Melbourne", "Port Adelaide", "Richmond",
			"St Kilda", "Sydney", "West Coast", "Western Bulldogs" };
%>
<%=i %>
<select name="Team<%=i %>">
<%for (String name : teamNames) { %>
<option value="<%=name %>" <%=roundLadder.getTeams().get(i).equalsIgnoreCase(name) ? "selected=\"selected\"" : ""%>><%=name %></option>
<%} %>

</select>



<br>

<%} %>

Valid - <select name="valid">
<option value="true"<%=roundLadder.getValid() ? "selected=\"selected\"" : "" %>>True</option>
<option value="false" <%=!roundLadder.getValid() ? "selected=\"selected\"" : "" %>>False</option>
</select>
    <input type="hidden" name="actionType" value="updateRound">
        <input type="hidden" name="Round" value="<%=round%>">

<P><INPUT TYPE=SUBMIT>
</form>



</body>
</html>